﻿using System;
using System.Collections;

namespace Mota.XMLControls
{
    public abstract class GuiTextBox : GuiControl
    {
        public override void Add(GuiControl guiControl)
        {
            //empty
        }

        public override IEnumerator GetEnumerator()
        {
            return null;
        }

        public virtual bool IsValid
        {
            get
            {
                return true;
            }
        }
        public override void Accept(GuiVisitor visitor)
        {
            visitor.Visit(this);
        }

        public abstract int MaxLength { get; set; }
        public abstract Char PasswordChar { get; set; }
        public override void SetPropertyValue(String propertyName, String propertyValue)
        {
            base.SetPropertyValue(propertyName, propertyValue);
            // chesh null or empty
            if (String.IsNullOrEmpty(propertyValue) || String.IsNullOrEmpty(propertyValue))
                return;

            // choose properties only from allowed 
            switch (propertyName)
            {
                case "MaxLength":
                    int parsedLengthMax;
                    if (int.TryParse(propertyValue, out parsedLengthMax))
                    {
                        this.MaxLength = parsedLengthMax;
                    }
                    break;
                case "PasswordChar":
                    this.PasswordChar = propertyValue[0];
                    break;
            }
        }

    }
}
